<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>事件冒泡</title>
  <style>
    #outer {
      width: 300px;
      height: 300px;
      background-color: cornflowerblue;
    }
    #center {
      width: 200px;
      height: 200px;
      background-color: orange;
      margin: 0 auto;
    }
    #inner {
      width: 100px;
      height: 100px;
      background-color: palevioletred;
      margin: 0 auto;
    }
  </style>
  <script>
    window.onload = function() {
      // 1.获取绑定事件的dom节点
      var outer = document.getElementById('outer')
      var center = document.getElementById('center')
      var inner = document.getElementById('inner')
      // 2.给目标节点绑定点击事件
      var num = 0
      outer.onclick = function(event) {
        num = 3
        // 阻止事件冒泡
        event.stopPropagation();
        console.log(num);
      }
      center.onclick = function(event) {
        num = 2
        // 阻止事件冒泡
        event.stopPropagation();
        console.log(num);
      }
      inner.onclick = function(event) {
        num = 1
        // 阻止事件冒泡
        event.stopPropagation();
        console.log(num);
      }
      
    }
  </script>
</head>
<body>
  <div id="outer">
    outer
    <div id="center">
      center
      <div id="inner">
        inner
      </div>
    </div>
  </div>
</body>
</html>